
package ch.hearc.coursJava.moo;

import java.util.LinkedList;
import java.util.List;



public class Pile<T>
	{

	/*------------------------------------------------------------------*\
	|*							Constructeurs							*|
	\*------------------------------------------------------------------*/

	public Pile()
		{
		this.list = new LinkedList<T>();
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Public							*|
	\*------------------------------------------------------------------*/

	public void push(T x)
		{
		list.add(x);
		}

	public T pop()
		{
		return list.remove(list.size()-1);
		}

	public T popSafe() throws Exception
		{
		if(!list.isEmpty())
			{
			return pop();
			}
		else
			{
			throw new Exception("Impossible de popper une pile vide");
			}
		}

	public int size()
		{
		return list.size();
		}

	@Override
	public String toString()
		{
		StringBuilder builder = new StringBuilder();
		builder.append("Pile [list=");
		builder.append(this.list);
		builder.append("]");
		return builder.toString();
		}

	/*------------------------------*\
	|*				Is				*|
	\*------------------------------*/



	public boolean isEmpty()
		{
		return list.isEmpty();
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	/*------------------------------------------------------------------*\
	|*							Attributs Private						*|
	\*------------------------------------------------------------------*/

	private List<T> list;


	}

